package com.chexiehui.jc.mvp.home;

import com.chexiehui.jc.Constants;
import com.chexiehui.jc.base.ApiCallback;
import com.chexiehui.jc.base.BaseModel;
import com.chexiehui.jc.base.BasePresenter;
import com.chexiehui.jc.entity.HomeMenuResultInfo;

/**
 * @Description 首页
 * @Auth SongJun
 * @Date 2019/11/20 10:05
 **/
public class HomePagePresenter extends BasePresenter<HomePageCovenant.View, HomePageCovenant.Stores>
        implements HomePageCovenant.Presenter {

    public HomePagePresenter(HomePageCovenant.View view) {
        attachView(view);
    }

    @Override
    public void getMenuData() {
        addSubscription(appStores.getMenuData(System.currentTimeMillis() + ""),
                new ApiCallback<BaseModel<HomeMenuResultInfo>>(mvpView) {
                    @Override
                    public void onSuccess(BaseModel<HomeMenuResultInfo> model) {
                        if (model.getResultCode() == Constants.REQUEST_OK_CODE) {
                            mvpView.onGeMenuDataSuccess(model);
                        } else {
                            onFailure(model.getResultCode(), model.getResultInfo());
                        }
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        mvpView.onGeMenuDataSuccess(new BaseModel<>(code, msg));
                    }
                });
    }

}